#include "adduserdialog.h"
#include "ui_adduserdialog.h"
#include <QMessageBox>

AddUserDialog::AddUserDialog(QWidget *parent)
    : QDialog(parent)
    , ui(new Ui::AddUserDialog)
{
    ui->setupUi(this);
    setWindowTitle("添加用户");

    // 设置密码框显示为密码形式
    ui->passwordEdit->setEchoMode(QLineEdit::Password);
    ui->confirmPasswordEdit->setEchoMode(QLineEdit::Password);
}

AddUserDialog::~AddUserDialog()
{
    delete ui;
}

QString AddUserDialog::getUsername() const
{
    return ui->usernameEdit->text();
}

QString AddUserDialog::getPassword() const
{
    return ui->passwordEdit->text();
}

void AddUserDialog::on_okButton_clicked()
{
    QString username = ui->usernameEdit->text();
    QString password = ui->passwordEdit->text();
    QString confirmPassword = ui->confirmPasswordEdit->text();

    // 验证输入
    if (username.isEmpty() || password.isEmpty()) {
        QMessageBox::warning(this, "输入错误", "用户名和密码不能为空！");
        return;
    }

    if (password != confirmPassword) {
        QMessageBox::warning(this, "输入错误", "两次输入的密码不一致！");
        return;
    }

    accept();
}

void AddUserDialog::on_cancelButton_clicked()
{
    reject();
}
